package com.sskj.mine.http;

import android.text.TextUtils;

import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.util.TipUtil;
import com.sskj.mine.bean.AddressList;
import com.sskj.mine.bean.AgentDataBean;
import com.sskj.mine.bean.ClientBean;
import com.sskj.mine.bean.CommissionBean;
import com.sskj.mine.bean.FbShop;
import com.sskj.mine.bean.MineAboutUsBean;
import com.sskj.mine.bean.MineGoogleBean;
import com.sskj.mine.bean.MineNoticeList;
import com.sskj.mine.bean.OtherRecordBean;
import com.sskj.mine.bean.PageBean;
import com.sskj.mine.bean.PayWayBean;
import com.sskj.mine.bean.QRCodeBean;
import com.sskj.mine.bean.RechargeListBean;
import com.sskj.mine.bean.AssetBean;
import com.sskj.mine.bean.CoinFeeBean;

import com.sskj.mine.bean.AssetBean;
import com.sskj.mine.bean.RechargeInfoBean;
import com.sskj.mine.bean.SysBean;
import com.sskj.mine.bean.UserAgreeMent;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.UserData;
import com.sskj.mine.bean.VerificationBean;

import java.io.File;
import java.util.List;
import java.util.Map;


/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {


    /**
     * 手机号注册
     *
     * @param account        手机号
     * @param pswd           密码
     * @param code           验证码
     * @param invitationCode 邀请码
     * @return
     */
    @Override
    public PostRequest<HttpData> register(String account, String pswd, String code, String invitationCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER)
                .params("account", account)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("code", code)
                .params("invitationCode", invitationCode);
    }


    /**
     * 获取短信验证码---codeType 1代表注册  2代表重置密码
     *
     * @param mobile   手机号
     * @param type
     * @param codeType
     * @param account  账号
     * @return
     */
    @Override
    public GetRequest<HttpData> sendCode(String mobile, String type, String codeType, String account) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("codeType", codeType)
                .params("account", account);
    }

    @Override
    public PostRequest<HttpData> bindChrome(String qrcode, String secret, String code, String stockUserId, String telCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_CHROME)
                .params("qrcode", qrcode)
                .params("secret", secret)
                .params("code", code)
                .params("stockUserId", stockUserId)
                .params("telCode", telCode);
    }


    /**
     * 登录
     *
     * @param pswd    密码
     * @param account 账号
     * @return
     */
    @Override
    public PostRequest<HttpData<UserData>> login(String account, String pswd) {
        return OkGo.<HttpData<UserData>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("account", account);
    }


    /**
     * 邮箱注册
     *
     * @param email          邮箱号
     * @param pswd           密码
     * @param code           验证码
     * @param invitationCode 邀请码
     * @return
     */
    @Override
    public PostRequest<HttpData> registerEmail(String email, String pswd, String code, String invitationCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER_WITH_EMAIL)
                .params("email", email)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("code", code)
                .params("invitationCode", invitationCode);
    }


    /**
     * @param email 邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> sendEmailCode(String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL_CODE)
                .params("email", email);
    }


    /**
     * 获取注册协议
     *
     * @return
     */
    @Override
    public GetRequest<HttpData<UserAgreeMent>> getXieyi() {
        return OkGo.<HttpData<UserAgreeMent>>get(HttpConfig.BASE_URL + HttpConfig.GET_XIEYI);
    }


    /**
     * 邮箱号重置密码
     *
     * @param code  验证码
     * @param pswd  新密码
     * @param email 账号
     * @return
     */
    @Override
    public PostRequest<HttpData> resetPwdWithEmail(String code, String pswd, String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_PWD_WITH_EMAIL)
                .params("code", code)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("email", email);
    }


    /**
     * 手机号重置密码
     *
     * @param code    验证码
     * @param pswd    新密码
     * @param account 账号
     * @return
     */
    @Override
    public PostRequest<HttpData> resetPwd(String code, String pswd, String account) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_PWD)
                .params("code", code)
                .params("pswd", MD5Util.getMd5Value(pswd))
                .params("account", account);
    }


    /**
     * 设置支付密码
     *
     * @param code     验证码
     * @param tradePwd 支付密码
     * @return
     */
    @Override
    public PostRequest<HttpData> setPayPwd(String code, String tradePwd, String mobile) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SET_PAY_PWD)
                .params("code", code)
                .params("account", mobile)
                .params("tradePwd", MD5Util.getMd5Value(tradePwd));
    }


    /**
     * 上传图片
     *
     * @param file 文件
     * @return
     */
    @Override
    public PostRequest<HttpData<String>> uploadImg(File file) {
        return OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.UPLOAD_IMG)
                .params("file", file);
    }


    /**
     * 绑定邮箱
     *
     * @param code  验证码
     * @param email 邮箱号
     * @return
     */
    @Override
    public PostRequest<HttpData> bindEmail(String code, String email) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_EMAIL)
                .params("code", code)
                .params("email", email);
    }


    /**
     * 实名认证
     *
     * @param username       用户名
     * @param idCardNo       身份证号
     * @param idCardFrontImg 前身份证
     * @param idCardBackImg  后身份证
     * @param selfieImg      手持
     * @return
     */
    @Override
    public PostRequest<HttpData> verify(String username, String idCardNo, String idCardFrontImg, String idCardBackImg, String selfieImg) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.VERIFY_IDENT)
                .params("username", username)
                .params("idCardNo", idCardNo)
                .params("idCardFrontImg", idCardFrontImg)
                .params("idCardBackImg", idCardBackImg)
                .params("selfieImg", selfieImg);
    }


    /**
     * 获取资产列表
     *
     * @return
     */
    @Override
    public PostRequest<HttpData<List<AssetBean>>> getAssets() {
        return OkGo.<HttpData<List<AssetBean>>>post(HttpConfig.BASE_URL + HttpConfig.ASSET_LIST);
    }


    /**
     * 获取提现手续费
     *
     * @param code 币种码
     * @return
     */
    @Override
    public PostRequest<HttpData<CoinFeeBean>> getWithdrawFee(String code) {
        return OkGo.<HttpData<CoinFeeBean>>post(HttpConfig.BASE_URL + HttpConfig.GET_COIN_FEE)
                .params("code", code);
    }


    /**
     * 充值
     *
     * @param code 币种码
     * @param type 类型 ETH 1，BTC 2，BCH 3
     * @return
     */
    @Override
    public PostRequest<HttpData<RechargeInfoBean>> recharge(String code, String type) {
        return OkGo.<HttpData<RechargeInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.RECHARGE_URL)
                .params("code", code)
                .params("type", type);
    }


    /**
     * 提现
     *
     * @param code       验证码
     * @param tradePwd   交易密码
     * @param usdFee     金额
     * @param walletAddr 钱包地址
     * @param stockCode  币种码
     * @return
     */
    @Override
    public PostRequest<HttpData> withdraw(String code, String tradePwd, String usdFee, String walletAddr, String stockCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW)
                .params("code", code)
                .params("tradePwd", MD5Util.getMd5Value(tradePwd))
                .params("usdFee", usdFee)
                .params("walletAddr", walletAddr)
                .params("stockCode", stockCode);
    }


    /**
     * 冲提币记录
     *
     * @return
     */
    @Override
    public GetRequest<HttpData<PageBean<RechargeListBean>>> getAssetRecord(int page, int pageSize, String type, String stockCode) {
        return OkGo.<HttpData<PageBean<RechargeListBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASSET_RECORD)
                .params("page", page)
                .params("pageSize", pageSize)
                .params("type", type)
                .params("stockCode", stockCode);
    }

    @Override
    public PostRequest<HttpData<PageBean<OtherRecordBean>>> getOtherRecord(int page, int pageSize, String stockCode) {
        return OkGo.<HttpData<PageBean<OtherRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.OTHER_RECORD)
                .params("page", page)
                .params("pageSize", pageSize)
                .params("stockCode", stockCode);
    }


    /**
     * 添加钱包地址
     *
     * @param type   类型 ETH 1，BTC 2，BCH 3
     * @param addr   钱包地址
     * @param code   币种码
     * @param remark 备注
     * @return
     */
    @Override
    public PostRequest<HttpData> addWalletAddress(String type, String addr, String code, String remark) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_ADD)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
//                .params("type", type)
                .params("addr", addr)
                .params("code", code)
                .params("remark", remark);
    }


    /**
     * 获取钱包列表
     *
     * @return
     */
    @Override
    public GetRequest<Map> getWalletList() {
        return OkGo.<Map>get(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""));
    }


    /**
     * 删除钱包地址
     *
     * @param id 钱包地址Id
     * @return
     */
    @Override
    public PostRequest<HttpData> delWalletAddress(String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_DEL)
                .params("id", Double.valueOf(id).intValue());
    }

    @Override
    public GetRequest<HttpData> changePwd(String account, String originPwd, String newPwd) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.CHANGE_PWD)
                .params("account", account)
                .params("newPswd", MD5Util.getMd5Value(newPwd))
                .params("pswd", MD5Util.getMd5Value(originPwd));

    }

    @Override
    public PostRequest<HttpData> bindMobile(String mobile, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_MOBILE)
                .params("account", mobile)
                .params("code", code);

    }

    @Override
    public PostRequest<HttpData> unBindMobile(String mobile, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UNBIND_EMAIL)
                .params("id", SPUtil.get(SPConfig.ID, ""))
                .params("email", mobile)
                .params("code", code);

    }

    @Override
    public PostRequest<HttpData> applyAgent(String name, String phone) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.APPLY_AGENT)
                .params("username", name)
                .params("tel", phone);
    }

    @Override
    public GetRequest<HttpData<AgentDataBean>> getAgentData() {
        return OkGo.<HttpData<AgentDataBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_AGENT_DATA);
    }

    @Override
    public GetRequest<HttpData<QRCodeBean>> getSpreadCode(String userId) {
        return OkGo.<HttpData<QRCodeBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_SPREAD_CODE)
                .params("id", userId);


    }

    @Override
    public GetRequest<HttpData<PageBean<CommissionBean>>> getCommission(int page) {
        return OkGo.<HttpData<PageBean<CommissionBean>>>get(HttpConfig.BASE_URL + HttpConfig.GET_COMMISSION)
                .params("page", page)
                .params("pageSize", 20);

    }

    @Override
    public GetRequest<HttpData<PageBean<ClientBean>>> getClient(int page) {
        return OkGo.<HttpData<PageBean<ClientBean>>>get(HttpConfig.BASE_URL + HttpConfig.GET_CLINET)
                .params("page", page)
                .params("pageSize", 20);
    }

    @Override
    public GetRequest<HttpData<UserData>> getUserInfo(String id) {
        return OkGo.<HttpData<UserData>>get(HttpConfig.BASE_URL + HttpConfig.GET_USET_INFO)
                .params("id", id);
    }

    @Override
    public PostRequest<HttpData<VerificationBean>> verificationJunior(String id, String username, String idCardNo) {
        return OkGo.<HttpData<VerificationBean>>post(HttpConfig.BASE_URL + HttpConfig.MINE_VERIFICATION_JUNIOR)
                .params("id", id)
                .params("username", username)
                .params("idCardNo", idCardNo);
    }

    @Override
    public GetRequest<HttpData> setShopName(String id, String nickname) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.MINE_SHOP_NAME)
                .params("id", id)
                .params("nickname", nickname);
    }

    @Override
    public GetRequest<HttpData> setMineTxName(String id, String headUrl) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.MINE_SHOP_NAME)
                .params("id", id)
                .params("headUrl", headUrl);
    }

    @Override
    public GetRequest<HttpData> openChrome(String id, String code) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.MINE_OPEN_GOOGLE)
                .params("stockUserId", id)
                .params("code", code);
    }

    @Override
    public GetRequest<HttpData> closeChrome(String id, String code, String telCode) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.MINE_CLOSE_GOOGLE)
                .params("stockUserId", id)
                .params("code", code)
                .params("telCode", telCode);
    }

    @Override
    public PostRequest<HttpData<com.sskj.lib.bean.PageBean<MineNoticeList>>> getGGList(String page, String pageSize) {
        return OkGo.<HttpData<com.sskj.lib.bean.PageBean<MineNoticeList>>>post(HttpConfig.BASE_URL + HttpConfig.NOTICE)
                .params("page", page)
                .params("pageSize", pageSize);
    }

    @Override
    public GetRequest<HttpData<List<SysBean>>> getSys(String type) {
        return OkGo.<HttpData<List<SysBean>>>get(HttpConfig.BASE_URL + HttpConfig.GET_SYS)
                .params("type", type);

    }

    @Override
    public GetRequest<HttpData<MineAboutUsBean>> getWebAboutUs() {
        return OkGo.<HttpData<MineAboutUsBean>>get(HttpConfig.BASE_URL + HttpConfig.ABOUT_US);
    }

    @Override
    public PostRequest<HttpData<List<PayWayBean>>> getPayType() {
        return OkGo.<HttpData<List<PayWayBean>>>post(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST);
    }

    @Override
    public PostRequest<HttpData> addPayWay(String payId, String payType, String tradePwd, String wxAccount, String wxImg, String alipayAccount, String aliImg, String bankCardNo, String bankCardOpenBank, String bankCardType) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_PAY_WAY)
                .params("payType", payType)
                .params("payId", payId)
                .params("tradePwd", MD5Util.getMd5Value(tradePwd))   // 最开始接口传两个密码
                .params("wxAccount", wxAccount)
                .params("wxImg", wxImg)
                .params("alipayAccount", alipayAccount)
                .params("aliImg", aliImg)
                .params("bankCardNo", bankCardNo)
                .params("bankCardOpenBank", bankCardOpenBank)
                .params("bankCardType", bankCardType);
    }

    @Override
    public PostRequest<HttpData> applyShop(String status) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.APPLY_SELLER)
                .params("isShopStatus", status);
    }

    @Override
    public PostRequest<HttpData> togglePayType(String id, boolean status) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TOGGLE_PAY)

                .params("payId", id)
                .params("disable", status);
    }

    @Override
    public PostRequest<HttpData<MineGoogleBean>> bindGoogle(String id) {
        return OkGo.<HttpData<MineGoogleBean>>post(HttpConfig.BASE_URL + HttpConfig.MINE_BIND_GOOGLE)
                .params("stockUserId", id);
    }

    @Override
    public PostRequest<HttpData<List<FbShop>>> moneyUsed(String name, String type) {
        return OkGo.<HttpData<List<FbShop>>>post(HttpConfig.BASE_URL + HttpConfig.FB_SHOP)
                .params("name", name)
                .params("type", type);
    }


    /**
     * Google验证登录
     *
     * @param code        随机验证码
     * @param stockUserId 当前登录用户ID
     * @return
     */
    @Override
    public GetRequest<HttpData> googleAuthVerify(String code, String stockUserId) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.GOOGLE_AUTH_VERIFY)
                .params("code", code)
                .params("stockUserId", stockUserId);
    }


}